package com.ilibrary.service.impl;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

import com.ilibrary.db.dao.hibernate.CategoryDao;
import com.ilibrary.db.entity.Category;
import com.ilibrary.service.CategoryService;
import com.ilibrary.web.dto.ResultDto;
import com.ilibrary.web.vo.CategoryVO;

public class CategoryServiceImpl implements CategoryService {
	
	private CategoryDao categoryDao;

	public CategoryDao getCategoryDao() {
		return categoryDao;
	}
	public void setCategoryDao(CategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}
	@Override
	public ResultDto<CategoryVO> findAll() {
		ResultDto<CategoryVO> resultDto = new ResultDto<CategoryVO>();
		List<Category> categoryList = categoryDao.findAll();
		CategoryVO categoryVO = null;
		for (Category category : categoryList) {
			categoryVO = new CategoryVO();
			try {
				BeanUtils.copyProperties(categoryVO, category);
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			}
			resultDto.addToResultList(categoryVO);
		}
		return resultDto;
	}
	
}
